package week2.day12;

/**
 * @Author fengzihao
 * @Date 2024-04-26 20:45
 */
public class TestLibrary {
    public static void main(String[] args) {
        Library library = new Library();
        library.addBook("红高粱","莫言");
        library.addBook("红楼梦","曹雪芹");
        library.addBook("活着","余华");
        library.addBook("三体","刘慈欣");
        library.addBook("围城","钱钟书");
        library.displayBooks();
    }
}
class Library{
    Book[] books = new Book[100];

    public void addBook(String title,String author){
        Book book = new Book(title,author);
        for (int i = 0; i < books.length; i++) {
            if (books[i] ==null){
                books[i] = book;
                break;
            }
        }
    }
    public void displayBooks(){
        for (Book book : books) {
            if (book == null)
                break;
            else
                book.displayInfo();
        }
    }
    static class Book{
        private String title;
        private String author;

        public Book(String title, String author) {
            this.title = title;
            this.author = author;
        }
        public void displayInfo(){
            System.out.println(toString());
        }
        @Override
        public String toString() {
            return "Book{" +
                    "title='" + title + '\'' +
                    ", author='" + author + '\'' +
                    '}';
        }
    }
}
